import { _decorator, assetManager, Component, director, SpriteFrame, } from 'cc'
import { ControllerManager } from '../UI/ControllerManager';
import { LoadingElement } from '../UI/LoadingElement';
import { userStore } from '../service/user';
import DataManager from '../Runtime/DataManager';
const { ccclass, property } = _decorator
const wx = window['wx']
@ccclass('LoadingManager')
export class LoadingManager extends Component {
  @property(SpriteFrame)
  preLoadingFrame: SpriteFrame = null;

  start() {
    const loadingElement = this.node.addComponent(LoadingElement)
    loadingElement.init(this.preLoadingFrame)
    this.preLoad()
    DataManager.Instance.room = null
    if (typeof (wx) !== "undefined") { //WX小游戏移动设备环境下
      var launch = wx.getLaunchOptionsSync();
      var query = launch.query;
      var room_number = query.roomNumber;
      if (room_number) {
        DataManager.Instance.shareNumber = room_number
      }
      else {
        console.log("微信平台无透传参数");
      }
    }
  }
  async preLoad() {
    var cloudUrl = "https://cocos-magical-fairy-1310297904.cos.ap-beijing.myqcloud.com/remote/resources/";
    assetManager.loadBundle(cloudUrl, async (err, bundle) => {
      console.log(err, bundle)
      let controllerManager = this.node.addComponent(ControllerManager)
      await controllerManager.loadAssortAssets()
      userStore().get().then(() => {
        director.loadScene('home')
      })
    });
  }
}

